export default {
    data() {
        return {
            tableData: [{
                tel: "18801414148",
                name: "admin",
                time: "2017-12-12   15:03",
                authority: "高级管理员",
            }],
            count: 0,
            page: 1,
            limit: 10,
            user_id: 0,
            user_mobile: '',
        }
    },
    //进入页面加载
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        //请求员工列表
        that.getUser();
    },

    methods: {
        // 请求员工列表api
        getUser: function () {
            var that = this;
            //初始化数据
            that.tableData = [];
            that.count = 0;

            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/manager/index", {
                token: that.token,
                id: that.user_id,
            }, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    if (res.body.list.list) {
                        for (var i in res.body.list.list) {
                            that.tableData.push({
                                i: i,
                                id: res.body.list.list[i].id,
                                tel: res.body.list.list[i].mobile,
                                name: res.body.list.list[i].username,
                                time: res.body.list.list[i].register_time,
                                authority: res.body.list.list[i].role_name,
                            });
                        }
                        that.count = res.body.list.count;
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        //下一页
        handleCurrentChange: function (currentPage) {
            var that = this;
            that.page = currentPage;
        },
        //添加城市轮播
        add: function () {
            var that = this;
            that.$router.push({path: '/set_up/add_user'});
        },
        //修改轮播
        edit: function (id) {
            var that = this;
            that.$router.push({path: '/set_up/add_user', query: {role_id: id}});
        },

        /**
         * 删除
         */
        deleteRole: function (e) {
            var that = this;
            that.$confirm('此操作将永久删除该员工, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.doDelete(e);
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        //执行删除
        doDelete: function (e) {
            var that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/manager/del", {
                token: that.token,
                id: e
            }, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    that.$message({
                        type: 'success',
                        message: `操作提示: ${ '删除成功' }`
                    });
                    that.getUser();
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },
        toMenu_manag:function(){
        	var that = this;
            that.$router.push({path: '/set_up/menu_management'});
        },
        toRoles:function(){
        	var that = this;
            that.$router.push({path: '/set_up/roles_manag'});
        }
    }
}